package com.bw.common;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import feign.Logger;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @author 13096
 */
@Configuration
public class MyRestTemplateConfig {
    /**
     * restTemplate实例
     * 为RestTemplate添加负载均衡能力
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * 更换ribbon负载均衡算法为随机
     * @return
     */
    @Bean
    IRule myRule() {
        return new RandomRule();
    }
    /**
     * fegin调用日志
     */
    @Bean
    Logger.Level feignLogLevel() {
        return Logger.Level.FULL;
    }

}

